<%@ page import="java.util.ArrayList" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<jsp:useBean id="ogrenci" class="siniflar.Ogrenci" scope="session" />
<jsp:useBean id="ogrenciKalinanDersler" type="ArrayList<siniflar.Ders>" scope="session" />
<jsp:useBean id="ogrenciAlinacakDersler" type="ArrayList<siniflar.Ders>" scope="session" />

<%
    String ogrenciDersKayitDurum = (String)session.getAttribute("ogrenciDersKayitDurum"); 
%>

<jsp:include page="../ek_bas.jsp" />
<title>Ders Kaydı</title>
<script type="text/javascript">
    function checkboxAc(isim) {
        uzunluk = document.getElementsByName(isim).length;
        for(i = 0; i < uzunluk; i++) {
            document.getElementsByName(isim)[i].disabled=false;
        }
    }
</script>
<jsp:include page="ek_menu.jsp" />
<h1 class="icbaslik derskaydiicon">Ders Kaydı</h1>
    
    <%
        if(ogrenciDersKayitDurum != null) {
            out.print(ogrenciDersKayitDurum);
            session.removeAttribute("ogrenciDersKayitDurum");
        }
    %>
    
    <form action="DersKaydiYap" method="POST">
    <table>
        <tr class="tablobaslik">
            <td class="altkenarlikli">Ders Kodu</td>
            <td class="altkenarlikli">Ders Adı</td>
            <td class="altkenarlikli">Ders Kredisi</td>
            <td class="altkenarlikli">Ders Tipi</td>
            <td class="altkenarlikli">Seçim</td>
        </tr>
    <%
        if(ogrenciKalinanDersler.size() > 0) {
            out.print("<tr class=\"tablobaslik\"><td class=\"altkenarlikli ortali\" colspan=\"5\">Önceki Dönemlerden Kalınan Dersler</td></tr>");
            for(int i=0; i<ogrenciKalinanDersler.size(); i++){
                out.println("<tr class=\"r"+(i%2)+"\">");
                    out.println("<td>");
                    out.print(ogrenciKalinanDersler.get(i).getDersKodu()); 
                    out.println("</td>");
                    out.println("<td>");
                    out.print(ogrenciKalinanDersler.get(i).getDersAdi());
                    out.println("</td>");

                    out.println("<td>");
                    out.print(ogrenciKalinanDersler.get(i).getDersKredi());
                    out.println("</td>");

                    out.println("<td>");
                    out.print(ogrenciKalinanDersler.get(i).getDersTipi());
                    out.println("</td>");

                    out.println("<td>");
                    out.print("<input type=\"checkbox\" name=\"dersler\" value=\""+ogrenciKalinanDersler.get(i).getId() +"\" checked=\"\" disabled=\"\" />");
                    out.println("</td>");
                out.println("<tr>");
            }
        }
    
        out.print("<tr class=\"tablobaslik\"><td class=\"altkenarlikli ustkenarlikli ortali\" colspan=\"5\">İlk Defa Alınabilecek Dersler</td></tr>");
    
        for(int i=0; i<ogrenciAlinacakDersler.size(); i++){
            out.println("<tr class=\"r"+(i%2)+"\">");
                out.println("<td>");
                out.print(ogrenciAlinacakDersler.get(i).getDersKodu()); 
                out.println("</td>");
                out.println("<td>");
                out.print(ogrenciAlinacakDersler.get(i).getDersAdi());
                out.println("</td>");

                out.println("<td>");
                out.print(ogrenciAlinacakDersler.get(i).getDersKredi());
                out.println("</td>");
                out.println("<td>");
                out.print(ogrenciAlinacakDersler.get(i).getDersTipi());
                out.println("</td>");

                out.println("<td>");
                out.print("<input type=\"checkbox\" name=\"dersler\" value=\""+ogrenciAlinacakDersler.get(i).getId()+"\" />");
                out.println("</td>");
            out.println("<tr>");
        }
        
    %>
    </table>
    <div class="yazilarsaga"><input type="submit" class="duzbuton" value="Ders Kaydı Gerçekleştir" onClick="javascript:checkboxAc('dersler')" /></div>
    </form>

<jsp:include page="../ek_son.jsp" />
